package com.yuzhi.common.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.time.temporal.TemporalAdjusters;

/**
 * 时间工具类
 */
public class DateTimeFilterUtils {

    // 获取当天的开始时间(00:00:00)
    public static LocalDateTime getStartOfToday() {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
    }

    // 获取当天的结束时间(23:59:59.999999999)
    public static LocalDateTime getEndOfToday() {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
    }

    // 获取昨天的开始时间
    public static LocalDateTime getStartOfYesterday() {
        return getStartOfToday().minusDays(1);
    }

    // 获取昨天的结束时间
    public static LocalDateTime getEndOfYesterday() {
        return getEndOfToday().minusDays(1);
    }

    // 获取当月开始时间
    public static LocalDateTime getStartOfMonth() {
        return LocalDateTime.of(LocalDate.now().withDayOfMonth(1), LocalTime.MIN);
    }

    // 获取当月结束时间
    public static LocalDateTime getEndOfMonth() {
        return LocalDateTime.of(
                LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()),
                LocalTime.MAX
        );
    }

    // 获取当年开始时间
    public static LocalDateTime getStartOfYear() {
        return LocalDateTime.of(
                LocalDate.now().withDayOfYear(1),
                LocalTime.MIN
        );
    }

    // 获取当年结束时间
    public static LocalDateTime getEndOfYear() {
        return LocalDateTime.of(
                LocalDate.now().with(TemporalAdjusters.lastDayOfYear()),
                LocalTime.MAX
        );
    }
}
